var funcIndex = 0;
function getCrossCallback(func) {
    funcIndex++;

    var i = funcIndex.toString();

    crossCallback[i] = func;

    return i;
}


var backupSetkey=WebUIJS.SetActiveMenuKey;
var backupRefreshEvent=WebUIJS.RefreshEvent;

WebUIJS.RefreshEvent=function(collection,onsuccess){
    backupRefreshEvent(collection, onsuccess);
    
}


WebUIJS.SetActiveMenuKey=function (menuKey){
    backupSetkey(menuKey);
    WebUIJS.CrossCall("SetMenuKey", { MenuKey: menuKey });
}

WebUIJS.CrossCall = function (funcName, args, callback) {
    var callbackFuncID =0;// getCrossCallback(callback);

    var json = {
        Message: "Call",
        FuncName: funcName,
        Args: args,
        Callback: {
            FuncID: callbackFuncID
        }
    }

    if (callbackFuncID > 0) {
        json.Callback = {
            FuncID: callbackFuncID
        }
    }

    window.parent.postMessage(JSON.stringify(json), "*");
}

$(document).ready(function(){
    WebUIJS.CrossCall("SetTitle", {
        Title: document.title
    });
    //WebUIJS.CrossCall("SetMenuKey", { MenuKey: currentMenuKey });
})